//
//  HCGrowthAlbumViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/19.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCGrowthAlbumViewController.h"

#import "HCGrowthAlbumView.h"
#import "selectMainVC.h"
#import "CovertPhotoMethod.h"
#import "HCGrowAlumbModel.h"
#import "HCLogViewController.h"
#import "HCAlbumDetailController.h"

@interface HCGrowthAlbumViewController () <HCGrowthAlbumViewDelate> {
    HCGrowAlumbModel *model;
    HCGrowthAlbumView *albumView;
    HCPopLoadingView *popLoading;
}

@end

@implementation HCGrowthAlbumViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
   
    if ([PublicFunction isNull:HCGETUSER(@"userid")]) {

    }else{
        [self.dataRequest postHC_GrowShow:HCGETUSER(@"userid")];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"成长相册";
    albumView = [[HCGrowthAlbumView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    albumView.delegate = self;
    [self.centerView addSubview:albumView];
    
    __weak typeof (self)weakSelf = self;
    [albumView setClickUserHeadBlock:^{
       
        NSLog(@"点击用户头像");
        [weakSelf pushChildrenViewController:@"HCMindHeadViewController" parameterObject:nil dataObject:nil];
    }];
    
    [albumView setClickheadImageBlock:^(NSArray *images, NSString *timeText, NSString *contents){
        
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        if (contents.length != 0) {
            
            [dic setObject:contents forKey:@"content"];
        }
        if (timeText.length != 0) {
            
            [dic setObject:timeText forKey:@"time"];
        }
        [weakSelf pushChildrenViewController:@"HCAlbumDetailController" parameterObject:images dataObject:dic];
    }];
    
    
    self.dataRequest.delegate = self;
    if ([PublicFunction isNull:HCGETUSER(@"userid")]) {
        HCLogViewController *log = [[HCLogViewController alloc] init];
        
        UINavigationController *na = [[UINavigationController alloc] initWithRootViewController:log];
        na.navigationBarHidden = YES;
        [self.navigationController presentViewController:na animated:YES completion:nil];

    }else{
        popLoading = [[HCPopLoadingView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        [popLoading showAnimate];
    }
}

#pragma mark -- HCGrowthAlbumViewDelate
- (void)pushControllerd {
    
    [self pushChildrenViewController:@"HCGrouthViewController" parameterObject:nil dataObject:nil];
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    
    NSLog(@"成长相册数据:%@",dictionary);
    model = [[HCGrowAlumbModel alloc] initWithDictionary:dictionary error:nil];
    albumView.model = model;
    [popLoading hidden];
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {

    [popLoading hidden];
    [XHToast showBottomWithText:@"网络请求失败"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
